package dao

import (
	"ssims/models"
)

func GetAllSc(sc map[string]interface{}) (error, []models.Sc, int64) {
	var scData []models.Sc
	page := sc["page"].(int)
	pageSize := sc["limit"].(int)
	//searchName := sc["searchNo"].(int)
	var total int64
	err := db.Table("sc").Select("student_name, course_name, sc_grade, update_time").Where("is_del = false").Order("sc_grade ASC").Count(&total).Offset((page - 1) * pageSize).Limit(pageSize).Find(&scData).Error
	return err, scData, total
}
func GetNumber(sc map[string]interface{}) (error, []models.Tj, int64) {
	var numberDate []models.Tj
	// page := sc["page"].(int)
	// pageSize := sc["limit"].(int)
	//searchName := sc["searchNo"].(int)
	var total int64
	err := db.Table("sc").Select("sum(case when sc_grade between 90 and 100 then 1 else 0 end) as A, sum(case when sc_grade between 80 and 89 then 1 else 0 end) as B, sum(case when sc_grade between 70 and 79 then 1 else 0 end) as C, sum(case when sc_grade between 60 and 69 then 1 else 0 end) as D, sum(case when sc_grade < 60 then 1 else 0 end) as E").Count(&total).Find(&numberDate).Error
	return err, numberDate, total
}
func AddSc(sc models.Sc) error {
	err := db.Table("sc").Select("student_name", "course_name", "sc_grade", "update_time").Create(&sc).Error
	return err
}

func UpdateSc(sc models.Sc) error {
	err := db.Table("sc").Where("student_name = ?", sc.StudentName).Updates(&sc).Error
	return err
}

func DelSc(name string) error {
	err := db.Table("sc").Where("student_name = ?", name).Update("is_del", true).Error
	return err
}
